<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <title>ISeeAdmin 【复杂表格2】 </title>
    <!--    <link rel="stylesheet" href="/static/element/index.css">-->
    <link href="https://cdn.staticfile.org/element-ui/2.12.0/theme-chalk/index.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/iconfont/iconfont.css">
    <link rel="stylesheet" href="/static/css/common.css">
    <!--    开发环境-->
    <!--        <script src="/static/js/iseeadmin.js"></script>-->
    <!--    正式环境-->
    <script src="/static/js/iseeadmin.min.js"></script>
    <script src="/static/js/menu.js"></script>
    <!--    开发环境-->
    <!--    <script src="/static/js/vue.js"></script>-->
    <!--    正式环境-->
    <!--        <script src="/static/js/vue.min.js"></script>-->
    <script src="https://cdn.staticfile.org/vue/2.6.10/vue.min.js"></script>
    <!--    <script src="/static/element/index.js"></script>-->
    <script src="https://cdn.staticfile.org/element-ui/2.12.0/index.js"></script>
    <!--    <script src="/static/js/axios.min.js"></script>-->
    <style>
        .demo-table-expand {
            font-size: 0;
        }

        .demo-table-expand label {
            width: 90px;
            color: #99a9bf;
        }

        .demo-table-expand .el-form-item {
            margin-right: 0;
            margin-bottom: 0;
            width: 50%;
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <el-container style="height: 100%;min-height:100vh;">
        <el-aside v-show="iseeData.asideShow" width="210px">
            <!--            左侧logo 开始-->
            <div class="aside-logo">
                <img class="aside-logo-img" src="/static/images/logo.png"
                     alt=""> ISeeAdmin
            </div>
            <!--            左侧logo 结束-->
            <!--            左侧菜单 开始-->
            <el-menu @select="iseeMenuOpen" style="width: 210px;"
                     unique-opened
                     :default-active="iseeData.defaultActive"
                     background-color="#304156"
                     text-color="#bfcbd9"
                     active-text-color="#409eff">
                <iseemenu :menu="iseeData.menu"></iseemenu>
            </el-menu>
            <!--            左侧菜单 结束-->
        </el-aside>

        <el-container>
            <el-header height="83px">
                <div class="isee-header-div">
                    <!--                    面包屑 开始-->
                    <div style="width: 100%;display: inherit;">
                        <span class="aside-show" @click="iseeAsideShow">
                            <i :class="iseeData.asideShowIcon"></i>
                        </span>

                        <el-breadcrumb style="line-height: 50px" separator="/">
                            <el-breadcrumb-item v-for="(item,index) in iseeData.breadcrumb" :key="index">{{item.title}}
                            </el-breadcrumb-item>
                        </el-breadcrumb>
                    </div>
                    <!--                    面包屑 结束-->
                    <!--                    icon功能列表，可根据需要修改 开始-->
                    <div>
                        <ul class="isee-ul">
                            <li class="isee-li">
                                <i style="font-size: 20px" class="el-icon-bell"></i>
                            </li>
                            <li @click="iseeFullScreen" class="isee-li">
                                <span class="iconfont" style="font-size: 20px" v-html="iseeData.fullscreenIcon"></span>
                            </li>
                            <li class="isee-li" @click="iseeData.drawer = true">
                                <span class="iconfont" style="font-size: 20px">&#xe602;</span>
                            </li>
                        </ul>
                    </div>
                    <!--                    icon功能列表，可根据需要修改 结束-->
                    <!--                    avatar显示 开始-->
                    <div>
                        <el-dropdown @command="iseeOpenUrl">
                              <span class="el-dropdown-link">
                                  <el-avatar style="margin-top: 9px" :size="iseeData.avatar.size"
                                             :src="iseeData.avatar.url"></el-avatar>
                              </span>

                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item v-for="(item,index) in iseeData.avatar.list" :icon="item.icon"
                                                  :key="index" :command="index">{{item.title}}
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                    <!--                    avatar显示 结束-->
                </div>
                <div style="display: flex">
                    <!--                    标签页列表 开始-->
                    <span @click="iseeTagDivMove(1)" class="isee-tag-span">
                        <i class="el-icon-d-arrow-left"></i>
                    </span>
                    <div ref="iseeTagDiv" class="isee-tag-div">
                        <el-tag style="cursor:pointer;margin-right: 5px;" v-for="(item,index) in iseeData.tagList"
                                :key="index"
                                @click="iseeTagSwitch(item.url,item.index,item.breadcrumb)"
                                :effect="item.effect"
                                :type="item.type"
                                @close="iseeTagClose(item.url,index)"
                                size="medium"
                                :closable="item.closable"><i v-show="item.show" class="el-icon-view"></i> {{item.title}}
                        </el-tag>
                    </div>
                    <span @click="iseeTagDivMove(2)" class="isee-tag-span">
                        <i class="el-icon-d-arrow-right"></i>
                    </span>
                    <!--                    标签页列表 结束-->
                    <!--                    标签页集中操作 开始-->
                    <div style="float: right;">
                        <el-dropdown @command="iseeTagCommandClose">
                          <span class="el-dropdown-link">
                              <i class="el-icon-arrow-down isee-el-icon-arrow-down"></i>
                          </span>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item command="1">关闭当前标签页</el-dropdown-item>
                                <el-dropdown-item command="2">关闭其它标签页</el-dropdown-item>
                                <el-dropdown-item command="3">关闭全部标签页</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                    <!--                    标签页集中操作 结束-->
                </div>

                <!--抽屉式展示-->
                <el-drawer
                        title="iseeAdmin"
                        :visible.sync="iseeData.drawer"
                        :direction="iseeData.direction"
                        :show-close="iseeData.showClose"
                        custom-class="isee-drawer-info"
                >
                    <el-divider></el-divider>
                    <div style="font-size: 14px">
                        <p class="isee-title">版本信息</p>
                        <ul class="isee-drawer-ul">
                            <li>
                                当前版本：iseeAdmin-v{{iseeData.version}}
                            </li>
                            <li>
                                基于框架：vue v2.6.10，element v2.12.0
                            </li>
                            <li>
                                下载地址：
                                <el-link type="primary" :underline="false" href="https://gitee.com/youge/iseeadmin"
                                         target="_blank">https://gitee.com/youge/iseeadmin
                                </el-link>
                            </li>
                        </ul>
                    </div>
                    <el-divider></el-divider>
                    <div style="font-size: 14px">
                        <p class="isee-title">关于版权</p>
                        <ul class="isee-drawer-ul">
                            <li>
                                iseeAdmin完全开源，可免费使用
                            </li>
                            <li>
                                QQ交流群：927049524
                            </li>
                        </ul>
                    </div>
                </el-drawer>
                <!--抽屉式展示 结束-->
            </el-header>

            <el-main>
                <!--                主内容展示-->
                <div style="margin-right: 10px">
                    <el-card class="box-card">
                        Table 表格
                        <el-link type="primary" target="_blank"
                                 href="https://element.eleme.cn/#/zh-CN/component/table">
                            官方文档 https://element.eleme.cn/#/zh-CN/component/table
                        </el-link>
                    </el-card>
                </div>
                <div style="display: flex">
                    <el-card class="box-card">

                        <el-divider content-position="left"><span
                                class="el-divider-span">树形数据与懒加载 <el-tooltip
                                content="支持树类型的数据的显示。当 row 中包含 children 字段时，被视为树形数据。渲染树形数据时，必须要指定 row-key。支持子节点数据异步加载。设置 Table 的 lazy 属性为 true 与加载函数 load 。通过指定 row 中的 hasChildren 字段来指定哪些行是包含子节点。children 与 hasChildren 都可以通过 tree-props 配置。"
                                placement="top" effect="light"><i
                                class="el-icon-info" style="color: gray"></i></el-tooltip></span></el-divider>
                        <template>
                            <div>
                                <el-table
                                        :data="tableData"
                                        style="width: 100%;margin-bottom: 20px;"
                                        row-key="id"
                                        border
                                        default-expand-all
                                        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                                    <el-table-column
                                            prop="date"
                                            label="日期"
                                            sortable
                                            width="180">
                                    </el-table-column>
                                    <el-table-column
                                            prop="name"
                                            label="姓名"
                                            sortable
                                            width="180">
                                    </el-table-column>
                                    <el-table-column
                                            prop="address"
                                            label="地址">
                                    </el-table-column>
                                </el-table>

                                <el-table
                                        :data="tableData1"
                                        style="width: 100%"
                                        row-key="id"
                                        border
                                        lazy
                                        :load="load"
                                        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                                    <el-table-column
                                            prop="date"
                                            label="日期"
                                            width="180">
                                    </el-table-column>
                                    <el-table-column
                                            prop="name"
                                            label="姓名"
                                            width="180">
                                    </el-table-column>
                                    <el-table-column
                                            prop="address"
                                            label="地址">
                                    </el-table-column>
                                </el-table>
                            </div>
                        </template>

                        <el-divider content-position="left"><span
                                class="el-divider-span">表尾合计行 <el-tooltip
                                content="若表格展示的是各类数字，可以在表尾显示各列的合计。将show-summary设置为true就会在表格尾部展示合计行。默认情况下，对于合计行，第一列不进行数据求合操作，而是显示「合计」二字（可通过sum-text配置），其余列会将本列所有数值进行求合操作，并显示出来。当然，你也可以定义自己的合计逻辑。使用summary-method并传入一个方法，返回一个数组，这个数组中的各项就会显示在合计行的各列中，具体可以参考本例中的第二个表格。"
                                placement="top" effect="light"><i
                                class="el-icon-info" style="color: gray"></i></el-tooltip></span></el-divider>
                        <template>
                            <el-table
                                    :data="tableData2"
                                    border
                                    show-summary
                                    style="width: 100%">
                                <el-table-column
                                        prop="id"
                                        label="ID"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="name"
                                        label="姓名">
                                </el-table-column>
                                <el-table-column
                                        prop="amount1"
                                        sortable
                                        label="数值 1">
                                </el-table-column>
                                <el-table-column
                                        prop="amount2"
                                        sortable
                                        label="数值 2">
                                </el-table-column>
                                <el-table-column
                                        prop="amount3"
                                        sortable
                                        label="数值 3">
                                </el-table-column>
                            </el-table>

                            <el-table
                                    :data="tableData2"
                                    border
                                    height="200"
                                    :summary-method="getSummaries"
                                    show-summary
                                    style="width: 100%; margin-top: 20px">
                                <el-table-column
                                        prop="id"
                                        label="ID"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="name"
                                        label="姓名">
                                </el-table-column>
                                <el-table-column
                                        prop="amount1"
                                        label="数值 1（元）">
                                </el-table-column>
                                <el-table-column
                                        prop="amount2"
                                        label="数值 2（元）">
                                </el-table-column>
                                <el-table-column
                                        prop="amount3"
                                        label="数值 3（元）">
                                </el-table-column>
                            </el-table>
                        </template>


                    </el-card>
                    <el-card class="box-card">
                        <el-divider content-position="left"><span
                                class="el-divider-span">自定义表头 <el-tooltip
                                content="通过设置 Scoped slot 来自定义表头" placement="top" effect="light"><i
                                class="el-icon-info" style="color: gray"></i></el-tooltip></span></el-divider>
                        <template>
                            <el-table
                                    :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
                                    style="width: 100%">
                                <el-table-column
                                        label="Date"
                                        prop="date">
                                </el-table-column>
                                <el-table-column
                                        label="Name"
                                        prop="name">
                                </el-table-column>
                                <el-table-column
                                        align="right">
                                    <template slot="header" slot-scope="scope">
                                        <el-input
                                                v-model="search"
                                                size="mini"
                                                placeholder="输入关键字搜索"/>
                                    </template>
                                    <template slot-scope="scope">
                                        <el-button
                                                size="mini"
                                                @click="handleEdit(scope.$index, scope.row)">Edit
                                        </el-button>
                                        <el-button
                                                size="mini"
                                                type="danger"
                                                @click="handleDelete(scope.$index, scope.row)">Delete
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>

                        <el-divider content-position="left"><span
                                class="el-divider-span">合并行或列 <el-tooltip
                                content="多行或多列共用一个数据时，可以合并行或列。通过给table传入span-method方法可以实现合并行或列，方法的参数是一个对象，里面包含当前行row、当前列column、当前行号rowIndex、当前列号columnIndex四个属性。该函数可以返回一个包含两个元素的数组，第一个元素代表rowspan，第二个元素代表colspan。 也可以返回一个键名为rowspan和colspan的对象。"
                                placement="top" effect="light"><i
                                class="el-icon-info" style="color: gray"></i></el-tooltip></span></el-divider>
                        <template>
                            <div>
                                <el-table
                                        :data="tableData2"
                                        :span-method="arraySpanMethod"
                                        border
                                        style="width: 100%">
                                    <el-table-column
                                            prop="id"
                                            label="ID"
                                            width="180">
                                    </el-table-column>
                                    <el-table-column
                                            prop="name"
                                            label="姓名">
                                    </el-table-column>
                                    <el-table-column
                                            prop="amount1"
                                            sortable
                                            label="数值 1">
                                    </el-table-column>
                                    <el-table-column
                                            prop="amount2"
                                            sortable
                                            label="数值 2">
                                    </el-table-column>
                                    <el-table-column
                                            prop="amount3"
                                            sortable
                                            label="数值 3">
                                    </el-table-column>
                                </el-table>

                                <el-table
                                        :data="tableData2"
                                        :span-method="objectSpanMethod"
                                        border
                                        style="width: 100%; margin-top: 20px">
                                    <el-table-column
                                            prop="id"
                                            label="ID"
                                            width="180">
                                    </el-table-column>
                                    <el-table-column
                                            prop="name"
                                            label="姓名">
                                    </el-table-column>
                                    <el-table-column
                                            prop="amount1"
                                            label="数值 1（元）">
                                    </el-table-column>
                                    <el-table-column
                                            prop="amount2"
                                            label="数值 2（元）">
                                    </el-table-column>
                                    <el-table-column
                                            prop="amount3"
                                            label="数值 3（元）">
                                    </el-table-column>
                                </el-table>
                            </div>
                        </template>


                        <el-divider content-position="left"><span
                                class="el-divider-span">自定义索引 <el-tooltip
                                content="自定义 type=index 列的行号。通过给 type=index 的列传入 index 属性，可以自定义索引。该属性传入数字时，将作为索引的起始值。也可以传入一个方法，它提供当前行的行号（从 0 开始）作为参数，返回值将作为索引展示。"
                                placement="top" effect="light"><i
                                class="el-icon-info" style="color: gray"></i></el-tooltip></span></el-divider>
                        <template>
                            <el-table
                                    :data="tableData"
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        :index="indexMethod">
                                </el-table-column>
                                <el-table-column
                                        prop="date"
                                        label="日期"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="name"
                                        label="姓名"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="address"
                                        label="地址">
                                </el-table-column>
                            </el-table>
                        </template>

                    </el-card>
                </div>
                <!--                主内容展示 结束-->
            </el-main>
        </el-container>
    </el-container>
</div>


<script>
  const iseeAvatar = {
    url: '/static/images/avatar01.gif',
    size: 32,
    list: [
      {
        index: '',
        indexPath: [],
        icon: 'el-icon-user-solid',
        url: '',
        target: '_self',
        title: 'admin',
      }, {
        index: '6-1-0',
        indexPath: ["6", "6-1", "6-1-0"],
        icon: 'el-icon-tickets',
        url: '/pages/sets/myset/profile.html',
        target: '_self',
        title: '基本资料',
      }, {
        index: '6-1-1',
        indexPath: ["6", "6-1", "6-1-1"],
        icon: 'el-icon-edit-outline',
        url: '/pages/sets/myset/password.html',
        target: '_self',
        title: '修改密码',
      }, {
        index: '',
        indexPath: [],
        icon: 'el-icon-switch-button',
        url: '',
        target: '_self',
        title: '安全退出',
      },
    ]
  }
  var iseemenu = {
    props: ['menu'],
    name: 'iseemenu',
    template: `
    <div>
        <template v-for="item in menu">
            <el-submenu :index="item.index" v-if="item.children.length">
                <template slot="title">
                    <i :class="item.icon"></i>
                    <span slot="title">{{item.title}}</span>
                </template>
                <iseemenu :menu="item.children"></iseemenu>
            </el-submenu>
            <el-menu-item :index="item.index" v-else>
                <i :class="item.icon"></i>
                <span slot="title">{{item.title}}</span>
            </el-menu-item>
        </template>
    </div>`,
  }
  var app = new Vue({
    el: '#app',
    components: {
      iseemenu
    },
    data: {
      iseeData: {
        version: iseeAdmin.version,
        drawer: false,
        direction: 'rtl',
        showClose: false,
        status: false,
        show: true,
        asideShow: iseeAdmin.asideShow,
        asideShowIcon: iseeAdmin.asideShowIcon,
        fullscreen: false,
        fullscreenIcon: '&#xe610;',
        defaultActive: iseeAdmin.defaultActive,
        tagList: iseeAdmin.tagList,
        breadcrumb: iseeAdmin.breadcrumb,
        menu: iseeMenu,
        avatar: iseeAvatar
      },
      /*your data*/
      tableData: [{
        id: 1,
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        id: 2,
        date: '2016-05-04',
        name: '张大虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        id: 3,
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄',
        children: [{
          id: 31,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: 32,
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }]
      }, {
        id: 4,
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      tableData1: [{
        id: 1,
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        id: 2,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        id: 3,
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄',
        hasChildren: true
      }, {
        id: 4,
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      tableData2: [{
        id: '12987122',
        name: '王小虎',
        amount1: '234',
        amount2: '3.2',
        amount3: 10
      }, {
        id: '12987123',
        name: '王小虎',
        amount1: '165',
        amount2: '4.43',
        amount3: 12
      }, {
        id: '12987124',
        name: '王小虎',
        amount1: '324',
        amount2: '1.9',
        amount3: 9
      }, {
        id: '12987125',
        name: '王小虎',
        amount1: '621',
        amount2: '2.2',
        amount3: 17
      }, {
        id: '12987126',
        name: '王小虎',
        amount1: '539',
        amount2: '4.1',
        amount3: 15
      }],
      search: ''

    },
    methods: {
      iseeTagSwitch(url, index, breadcrumb) {
        iseeAdmin.iseeTagSwitch(url, index, breadcrumb, this.iseeData)
      },

      iseeTagClose(url, index) {
        iseeAdmin.iseeTagClose(url, index, this.iseeData)
      },

      iseeTagCommandClose(command) {
        iseeAdmin.iseeTagCommandClose(command, this.iseeData)
      },

      iseeMenuOpen(key, keyPath) {
        iseeAdmin.iseeMenuOpen(key, keyPath, this.iseeData)
      },

      iseeFullScreen() {
        iseeAdmin.iseeFullScreen(this.iseeData)
      },

      iseeAsideShow() {
        iseeAdmin.iseeAsideShow(this.iseeData)
      },
      iseeOpenUrl(command) {
        iseeAdmin.iseeMenuOpen(this.iseeData.avatar.list[command].index, this.iseeData.avatar.list[command].indexPath, this.iseeData)
      },
      iseeTagDivMove(flag) {
        flag == 1 ? this.$refs.iseeTagDiv.scrollLeft += 80 : this.$refs.iseeTagDiv.scrollLeft -= 80
      },
      /*your methods*/
      load(tree, treeNode, resolve) {
        setTimeout(() => {
          resolve([
            {
              id: 31,
              date: '2016-05-01',
              name: '王小虎',
              address: '上海市普陀区金沙江路 1519 弄'
            }, {
              id: 32,
              date: '2016-05-01',
              name: '王小虎',
              address: '上海市普陀区金沙江路 1519 弄'
            }
          ])
        }, 1000)
      },

      handleEdit(index, row) {
        console.log(index, row);
      },

      handleDelete(index, row) {
        console.log(index, row);
      },

      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' 元';
          } else {
            sums[index] = 'N/A';
          }
        });
        return sums;
      },
      arraySpanMethod({row, column, rowIndex, columnIndex}) {
        if (rowIndex % 2 === 0) {
          if (columnIndex === 0) {
            return [1, 2];
          } else if (columnIndex === 1) {
            return [0, 0];
          }
        }
      },

      objectSpanMethod({row, column, rowIndex, columnIndex}) {
        if (columnIndex === 0) {
          if (rowIndex % 2 === 0) {
            return {
              rowspan: 2,
              colspan: 1
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }
      },
      indexMethod(index) {
        return index * 2;
      }

    },
    beforeMount() {
      iseeAdmin.init(this.iseeData)
      /*your beforeMount*/

    },
    mounted() {

    }
  });
</script>
</body>

</html>

